package com.design.testdemo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.design.testdemo.R;
import com.inuker.bluetooth.library.search.SearchResult;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Timmy on 2017/3/22.
 */

public class YiAdapter extends BaseAdapter {

    private List<SearchResult> mList = new ArrayList<>();
    private Context mContext;

    public YiAdapter(Context context) {
        mContext = context;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    public void setData(SearchResult data) {

        mList.add(data);
        notifyDataSetChanged();

    }

    public void delete(SearchResult data) {
        mList.remove(data);
        notifyDataSetChanged();
    }

    @Override
    public SearchResult getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item,null);
        }

        TextView viewById = (TextView) convertView.findViewById(R.id.tv_item);

        SearchResult searchResult = mList.get(position);

        viewById.setText(searchResult.getName());

        return convertView;
    }
}
